package cc.decat.escript.codegen;

import java.util.ArrayList;
import java.util.List;

public class BlockGenerate {
    public enum Type {
        NORMAL,
        FUNCTION,
        LAMBDA,
        LOOP,
        IF,
    }

    private Type type = Type.NORMAL;
    private BlockGenerate parent;
    private SymbolTable symbolTable;
    private List<BlockGenerate> childBlockGenerateList;
    private int indexOfParent; // 当前BlockGenerate在父级childBlockGenerateList的索引

    public BlockGenerate(BlockGenerate parent) {
        this.parent = parent;
        if(parent != null) {
            this.symbolTable = new SymbolTable(this);
        } else {
            this.symbolTable = new SymbolTable(null);
        }
        this.childBlockGenerateList = new ArrayList<>();
    }

    public int addChildBlockGenerate() {
        int index = this.getChildBlockGenerateList().size();
        this.getChildBlockGenerateList().add(new BlockGenerate(this));
        return index;
    }

    public BlockGenerate getParent() {
        return parent;
    }

    public SymbolTable getSymbolTable() {
        return symbolTable;
    }

    public void setSymbolTable(SymbolTable symbolTable) {
        this.symbolTable = symbolTable;
    }

    public List<BlockGenerate> getChildBlockGenerateList() {
        return childBlockGenerateList;
    }

    public void setType(Type type) {
        this.type = type;
    }

    public Type getType() {
        return type;
    }
}
